package main

import "fmt"

type Animal interface{
    Sleep()
    GetColor() string
    GetType() string
}

type Cat struct{
    Color string
}

func (this Cat) Sleep(){
    fmt.Println("Cat is Sleep...")
}

func (this Cat) GetColor() string {
    return this.Color
}

func (this Cat) GetType() string {
    return "Cat"
}

type Dog struct{
    Color string
}

func (this Dog) Sleep(){
    fmt.Println("Dog Sleep...")
}

func (this Dog) GetColor() string {
    return this.Color
}

func (this Dog) GetType() string {
    return "Dog"
}

func showAnimal(animal Animal){
    animal.Sleep()
    fmt.Println("color = ",animal.GetColor())
    fmt.Println("type = ",animal.GetType())
}

func main(){
    /*
    var animal Animal   //接口的数据类型，父类指针
    animal = &Cat{"Green"}  //调用的是Cat的Sleep方法，多态现象
    animal.Sleep()

    animal = &Dog{"Yellow"} //调用的是Cat的Sleep方法，多态现象
    animal.Sleep()
    */

    cat := Cat{"Green"}
    showAnimal(&cat)

    dog := Dog{"Green"}
    showAnimal(&dog)
}